local qulang = fk.CreateSkill {
  name = "lvshi__qulang",
  tags = { "Turn" },
}

Fk:loadTranslationTable{
  ["lvshi__qulang"] = "驭虓",
  [":lvshi__qulang"] = "回合技，当一名角色使用红色【杀】、【决斗】或勇策略锦囊时，你可以令其获得“恃勇”或“耀武”直到其下回合开始，然后与其各摸一张牌。",
  ["#lvshi__qulang-invoke"] = "驱虓：你可以令 %dest 获得“恃勇”或“耀武”直到其下回合开始",
  ["#lvshi__qulang-choice"] = "请选择要令 %dest 获得的技能",
  
  ["$lvshi__qulang1"] = "驱狼吞虎，以敌制敌。",
  ["$lvshi__qulang2"] = "借敌之力，破敌之阵。",
}

-- 检测是否为勇策略锦囊
local function isCourageStrategyCard(card, data)
  if card.type ~= Card.TypeTrick then return false end
  -- 检查是否为策略牌且为勇策略
  if data.extra_data and data.extra_data.strategy then
    return string.find(data.extra_data.strategy, "courage")
  end
  return false
end

-- 检测是否为符合条件的卡牌
local function isValidCard(card, data)
  -- 检测红色杀
  if card.trueName == "slash" and card.color == Card.Red then
    return true
  end
  -- 检测决斗
  if card.trueName == "duel" then
    return true
  end
  -- 检测勇策略锦囊
  return isCourageStrategyCard(card, data)
end

qulang:addEffect(fk.CardUsing, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(qulang.name) and player:usedSkillTimes(qulang.name) == 0
    and isValidCard(data.card, data)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    return room:askToSkillInvoke(player, {
      skill_name = qulang.name,
      prompt = "#lvshi__qulang-invoke::" .. target.id,
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 选择要给予的技能
    local choices = {"ls__shiyong", "ls__yaowu"}
    local choice = room:askToChoice(player, {
      choices = choices,
      skill_name = qulang.name,
      prompt = "#lvshi__qulang-choice::" .. target.id,
    })
    room:handleAddLoseSkills(target, choice, qulang.name)
    room:addTableMark(target, "qulang_skill-round", choice)
    --[[room.logic:getCurrentEvent():findParent(GameEvent.Round, true, Player.HistoryGame):addCleaner(function ()
      room:handleAddLoseSkills(target, "-" .. choice)
    end)]]
    target:drawCards(1, qulang.name)
    player:drawCards(1, qulang.name)
  end,
})

qulang:addEffect(fk.RoundEnd, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(qulang.name)
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      local skills = p:getTableMark("qulang_skill-round")
      for _, skill in ipairs(skills) do
        room:handleAddLoseSkills(p, "-" .. skill, qulang.name)
      end
    end
  end,
})

return qulang